﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using System.Data;
using System.Text;
using FineUI;

namespace lcmyjobs.Web.Admin.adverts
{
    public partial class Addpic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["adminName"] != null)
                {
                    if (Request["id"] != null)
                    {
                        Binddata(Request["id"].ToString());
                        btn_addpic.OnClientClick = win_addpic.GetShowReference("addpic_win.aspx?aid=" + Request["id"].ToString());
                        this.hf_aid.Text = Request["id"].ToString();
                        
                    }



                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='../adminlogin2.aspx'");
                }
            }
        }

        private void Binddata(string aid)
        {
            lcmyjobs.BLL.adverts bll = new lcmyjobs.BLL.adverts();
            DataSet ds = new DataSet();
            StringBuilder strWhere = new StringBuilder();
            string str = "aid = " + aid;
            str += " and apid is not null ";
            ds = bll.GetList(str);
            
            if (ds.Tables[0].Rows.Count > 0)
            {
                bindDdlList(ds.Tables[0].Rows[0]["locationid"].ToString());
                Grid1.DataSource = ds;
                Grid1.DataBind();
                if (Grid1.Rows.Count >= 3)
                {
                    btn_addpic.Visible = false;
                }
            }
        }

        private void binddata_bylocid(string locid)
        {
            lcmyjobs.BLL.adverts bll = new lcmyjobs.BLL.adverts();
            DataSet ds = new DataSet();
            StringBuilder strWhere = new StringBuilder();
            string str = "locationid = " + locid;
            str += " and apid is not null ";
            ds = bll.GetList(str);

            if (ds.Tables[0].Rows.Count > 0)
            {
                bindDdlList(ds.Tables[0].Rows[0]["locationid"].ToString());
                Grid1.DataSource = ds;
                Grid1.DataBind();
                if (Grid1.Rows.Count >= 3)
                {
                    btn_addpic.Visible = false;
                }

                this.hf_aid.Text = ds.Tables[0].Rows[0]["aid"].ToString();
            }

        }

        protected void Grid1_RowCommand(object sender, FineUI.GridCommandEventArgs e)
        {
            if (e.CommandName == "select")
            {
                //e.RowIndex
                
                object[] keys = Grid1.DataKeys[e.RowIndex];
                int apid = int.Parse(keys[0].ToString());
                int aid = int.Parse(this.hf_aid.Text.ToString());
                lcmyjobs.BLL.adverts adv = new lcmyjobs.BLL.adverts();
                adv.Updatepic(aid,apid);
                Binddata(this.hf_aid.Text.ToString());
            }
                /*
            else if (e.CommandName == "delete")
            {

            }
                 * */

        }
        protected void dononthing(object sender, EventArgs e)
        {
        }

        protected void btn_returnclick(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
        public static string selectdisplay(string isdisplay)
        {
            string res = "显示";
            if (isdisplay == "0" || isdisplay == "False")
            {
                res = "选择";
            }


            return res;
        }

        private void bindDdlList(string locid)
        {
            List<lcmyjobs.Model.ddllist> loclist = new List<lcmyjobs.Model.ddllist>();

            #region 下拉列表项
            loclist.Add(new lcmyjobs.Model.ddllist("0", "首页上中位"));
            loclist.Add(new lcmyjobs.Model.ddllist("1", "首页中上1行位"));
            loclist.Add(new lcmyjobs.Model.ddllist("2", "首页中上2行左1/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("3", "首页中上2行左2/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("4", "首页中上2行左3/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("5", "首页中上2行左4/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("6", "首页中上3行左1/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("7", "首页中上3行左2/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("8", "首页中上3行左3/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("9", "首页中上3行左4/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("10", "首页中上3行左5/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("11", "首页中上4行左1/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("12", "首页中上4行左2/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("13", "首页中上4行左3/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("14", "首页中上4行左4/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("15", "首页中上4行左5/5"));
            loclist.Add(new lcmyjobs.Model.ddllist("16", "求职中心首页上1行位"));
            loclist.Add(new lcmyjobs.Model.ddllist("17", "求职中心首页上2行左1/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("18", "求职中心首页上2行左2/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("19", "求职中心首页上2行左3/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("20", "求职中心首页上2行左4/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("21", "求职中心首页上3行左1/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("22", "求职中心首页上3行左2/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("23", "求职中心首页上3行左3/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("24", "求职中心首页上3行左4/4"));
            loclist.Add(new lcmyjobs.Model.ddllist("25", "招聘中心首页上位"));
            loclist.Add(new lcmyjobs.Model.ddllist("26", "单位介绍左位"));
            loclist.Add(new lcmyjobs.Model.ddllist("27", "猎头服务首页中位"));
            loclist.Add(new lcmyjobs.Model.ddllist("28", "悬赏招聘&bull;悬赏求职首页中位"));
            loclist.Add(new lcmyjobs.Model.ddllist("29", "个人管理中心上位"));
            loclist.Add(new lcmyjobs.Model.ddllist("30", "单位管理中心上位"));
            loclist.Add(new lcmyjobs.Model.ddllist("31", "在校生&bull;应届生首页中上左1/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("32", "在校生&bull;应届生首页中上左2/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("33", "在校生&bull;应届生首页中上左3/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("34", "在校生&bull;应届生首页中上左4/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("35", "在校生&bull;应届生首页中上左5/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("36", "在校生&bull;应届生首页中上左6/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("37", "在校生&bull;应届生首页中中左1/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("38", "在校生&bull;应届生首页中中左2/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("39", "在校生&bull;应届生首页中中左3/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("40", "在校生&bull;应届生首页中中左4/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("41", "在校生&bull;应届生首页中中左5/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("42", "在校生&bull;应届生首页中中左6/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("43", "在校生&bull;应届生首页中下左1/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("44", "在校生&bull;应届生首页中下左2/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("45", "在校生&bull;应届生首页中下左3/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("46", "在校生&bull;应届生首页中下左4/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("47", "在校生&bull;应届生首页中下左5/6"));
            loclist.Add(new lcmyjobs.Model.ddllist("48", "在校生&bull;应届生首页中下左6/6"));

            #endregion

            ddllocation.DataTextField = "Name";
            ddllocation.DataValueField = "ID";
            ddllocation.DataSource = loclist;
            ddllocation.DataBind();

            ddllocation.SelectedValue = locid;
            Grid1.Title = ddllocation.SelectedText;
        }

        protected void ddllocation_selected(object sender, EventArgs e)
        {
            binddata_bylocid(ddllocation.SelectedValue);
        }

        protected void Grid1_RowDataBound(object sender, FineUI.GridRowEventArgs e)
        {
            /*
            DataRowView row = e.DataItem as DataRowView;
            if (row != null)
            {
                //e.Values[4] = String.Format("{0} ({1})", e.Values[4], row["EntranceYear"]);
                if (row["strdisplay"] == "显示")
                {
                    highl
                }
            }
             * */
        }
    }
}